
package org.openeai.lite.common.util;

import org.apache.log4j.Logger;
import org.openeai.lite.common.control.ESBController;
import org.openeai.lite.common.exception.OpenEAIException;


public class ESBShutdownHook extends Thread
{

    private static Logger log = Logger.getLogger(ESBShutdownHook.class);

    private static final Object instanceLock = new Object();

    private static ESBShutdownHook instance = null;

    protected ESBShutdownHook()
    {
    }

    public static ESBShutdownHook getInstance()
    {
        synchronized (instanceLock)
        {
            if (instance == null)
            {
                instance = new ESBShutdownHook();
            }
            log.info("ESB shutdown hook registered.");
        }
        return instance;
    }

    @Override
    public void run()
    {
        try
        {
            if (ESBController.getInstance().isStarted())
            {
                ESBController.getInstance().stop();
            }
        }
        catch (OpenEAIException e)
        {
            //log.error(e.getMessage());
        }
    }

}
